package com.easou.ps.rpc.temp;

import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

import com.easou.ps.common.servicehandle.GBKCompactProtocol;
import com.easou.ps.thrift.qs.QSResult;
import com.easou.ps.thrift.search.mainsearch.MainSearchRequest;
import com.easou.ps.thrift.search.mainsearch.MainSearchResponse;
import com.easou.ps.thrift.search.mainsearch.MainSearchService;
import com.easou.ps.webmaster.SearchRequest;

public class MainSearchRPC {
	public static MainSearchResponse toSearch(SearchRequest req, QSResult qsResult){
		String address = "120.197.83.218";  
	    int port = 37000;
	    int clientTimeout = 30000;  
	    TTransport transport = new TFramedTransport(new TSocket(address, port, clientTimeout));  
	    try {  
	    	TProtocol protocol = new GBKCompactProtocol(transport);  
	    	MainSearchService.Client client = new MainSearchService.Client(protocol);  
	    	transport.open();  
	        MainSearchRequest request = new MainSearchRequest();
	        request.setQ(req.getQ());
	        request.setQsResult(qsResult);
	        request.setClearCache(req.getClearCache());
	        request.setSeqNo(0);
	        request.setDebug(req.isDebug());
	        MainSearchResponse resp = client.search(request);
	        if(resp!=null){
	        	System.out.println("resp.getDispNum():"+resp.getDispNum());
	        }else{
	        	System.out.println("resp == null");
	        }
	        transport.close(); 
	        return resp;
	    } catch (Exception e) {  
	        e.printStackTrace();  
	    }finally{
	    	transport.close(); 	    	
	    }
	    return null;
	}
}
